package com.adingxiong.pm.config;

import com.adingxiong.pm.handler.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;


@Configuration
public class WebConfigration implements WebMvcConfigurer {

    private static final List<String> EXCLUDE_PATH= Arrays.asList("/pm/webjars/**","/","/css/**",
            "/js/**","/img/**","/media/**","/vendors/**","/pm/v2/api-docs");
    @Bean
    public TokenInterceptor tokenInterceptor (){
        return new TokenInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //除了登录请求  其他所有请求都默认拦截
        registry.addInterceptor(tokenInterceptor())
                .excludePathPatterns(EXCLUDE_PATH)
                .addPathPatterns("/**")
               ;
        System.out.println("这是自定义拦截器 addIntercept");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");

        System.out.println("这是自定义拦截器 addResourceHandlers");

    }

}
